<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Navo Portable Library: navo/algorithm/hash/signature/sha256.h源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- 制作者 Doxygen 1.7.3 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Navo Portable Library&#160;<span id="projectnumber">Ver 1.0.20120827</span></div>
   <div id="projectbrief">Provides generic platform independent facilities.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="modules.html"><span>模块</span></a></li>
      <li><a href="annotated.html"><span>数据结构</span></a></li>
      <li class="current"><a href="files.html"><span>文件</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="搜索" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>文件列表</span></a></li>
      <li><a href="globals.html"><span>全局定义</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>navo/algorithm/hash/signature/sha256.h</h1>  </div>
</div>
<div class="contents">
<a href="sha256_8h.html">浏览该文件的文档。</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */</span>
<a name="l00011"></a>00011 <span class="preprocessor">#ifdef _MSC_VER</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span><span class="preprocessor">#pragma once</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* #ifdef _MSC_VER */</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="preprocessor">#ifndef __NV_SHA256__</span>
<a name="l00016"></a>00016 <span class="preprocessor"></span><span class="preprocessor">#define __NV_SHA256__</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="cdef_8h.html" title="Definitions and declarations for common constants, types, variables.">../../../port/cdef.h</a>&quot;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="integer_8h.html" title="Provides standard integer types.">../../../port/integer.h</a>&quot;</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include &lt;cstring&gt;</span>
<a name="l00023"></a>00023 <span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {
<a name="l00024"></a>00024 <span class="preprocessor">#else</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#endif  </span><span class="comment">/* #ifdef __cplusplus */</span>
<a name="l00027"></a>00027 
<a name="l00040"></a><a class="code" href="structsha256__ctx.html">00040</a> <span class="keyword">typedef</span> <span class="keyword">struct </span>{
<a name="l00042"></a><a class="code" href="structsha256__ctx.html#a6ed33b626cc641041136be1c87eaf9b8">00042</a>     uint32_t cnt[2];
<a name="l00044"></a><a class="code" href="structsha256__ctx.html#a21fb3008e4848b4432478a14ab53320b">00044</a>     uint32_t digest[8];
<a name="l00046"></a><a class="code" href="structsha256__ctx.html#a9d2ea15a1f7adcb120eee223458d9e28">00046</a>     <a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a> in[64];
<a name="l00047"></a>00047 }<a class="code" href="structsha256__ctx.html" title="SHA-256上下文">sha256_ctx</a>, <a class="code" href="structsha224__ctx.html" title="SHA-224上下文">sha224_ctx</a>;
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="preprocessor">#define SHA256_HASH_H0 0x6A09E667UL</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define SHA256_HASH_H1 0xBB67AE85UL</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define SHA256_HASH_H2 0x3C6EF372UL</span>
<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#define SHA256_HASH_H3 0xA54FF53AUL</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#define SHA256_HASH_H4 0x510E527FUL</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#define SHA256_HASH_H5 0x9B05688CUL</span>
<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#define SHA256_HASH_H6 0x1F83D9ABUL</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#define SHA256_HASH_H7 0x5BE0CD19UL</span>
<a name="l00057"></a>00057 <span class="preprocessor"></span>
<a name="l00058"></a>00058 <span class="preprocessor">#define SHA224_HASH_H0 0x6A09E667UL</span>
<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#define SHA224_HASH_H1 0xBB67AE85UL</span>
<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#define SHA224_HASH_H2 0x3C6EF372UL</span>
<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">#define SHA224_HASH_H3 0xA54FF53AUL</span>
<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define SHA224_HASH_H4 0x510E527FUL</span>
<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define SHA224_HASH_H5 0x9B05688CUL</span>
<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#define SHA224_HASH_H6 0x1F83D9ABUL</span>
<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#define SHA224_HASH_H7 0x5BE0CD19UL</span>
<a name="l00066"></a>00066 <span class="preprocessor"></span>
<a name="l00067"></a>00067 <span class="preprocessor">#define SHA256_SIZE 32</span>
<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#define SHA224_SIZE 28</span>
<a name="l00069"></a>00069 <span class="preprocessor"></span>
<a name="l00074"></a><a class="code" href="group__SHA-256__224.html#ga3f59e35bbeb37e935126641d69f90407">00074</a> <span class="preprocessor">#define SHA256_CTX(name) \</span>
<a name="l00075"></a>00075 <span class="preprocessor">    sha256_ctx name = {{0, 0}, {                                            \</span>
<a name="l00076"></a>00076 <span class="preprocessor">        SHA256_HASH_H0, SHA256_HASH_H1, SHA256_HASH_H2, SHA256_HASH_H3,     \</span>
<a name="l00077"></a>00077 <span class="preprocessor">        SHA256_HASH_H4, SHA256_HASH_H5, SHA256_HASH_H6, SHA256_HASH_H7}, {0}}</span>
<a name="l00078"></a>00078 <span class="preprocessor"></span>
<a name="l00083"></a><a class="code" href="group__SHA-256__224.html#ga66a63ff4bea37389ebea2ba1e553e980">00083</a> <span class="preprocessor">#define SHA224_CTX(name) \</span>
<a name="l00084"></a>00084 <span class="preprocessor">    sha256_ctx name = {{0, 0}, {                                            \</span>
<a name="l00085"></a>00085 <span class="preprocessor">        SHA224_HASH_H0, SHA224_HASH_H1, SHA224_HASH_H2, SHA224_HASH_H3,     \</span>
<a name="l00086"></a>00086 <span class="preprocessor">        SHA224_HASH_H4, SHA224_HASH_H5, SHA224_HASH_H6, SHA224_HASH_H7}, {0}}</span>
<a name="l00087"></a>00087 <span class="preprocessor"></span>
<a name="l00088"></a>00088 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> __sha256_init(uint32_t* digest, uint32_t* cnt)
<a name="l00089"></a>00089 {
<a name="l00090"></a>00090     digest[0] = SHA256_HASH_H0;
<a name="l00091"></a>00091     digest[1] = SHA256_HASH_H1;
<a name="l00092"></a>00092     digest[2] = SHA256_HASH_H2;
<a name="l00093"></a>00093     digest[3] = SHA256_HASH_H3;
<a name="l00094"></a>00094     digest[4] = SHA256_HASH_H4;
<a name="l00095"></a>00095     digest[5] = SHA256_HASH_H5;
<a name="l00096"></a>00096     digest[6] = SHA256_HASH_H6;
<a name="l00097"></a>00097     digest[7] = SHA256_HASH_H7;
<a name="l00098"></a>00098     cnt[0] = 0;
<a name="l00099"></a>00099     cnt[1] = 0;
<a name="l00100"></a>00100 }
<a name="l00101"></a>00101 
<a name="l00107"></a><a class="code" href="group__SHA-256__224.html#ga4685665d7ee57538983638f53e096869">00107</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group__SHA-256__224.html#ga4685665d7ee57538983638f53e096869" title="初始化SHA256上下文">sha256_init</a>(<a class="code" href="structsha256__ctx.html" title="SHA-256上下文">sha256_ctx</a>* ctx)
<a name="l00108"></a>00108 {
<a name="l00109"></a>00109     __sha256_init(ctx-&gt;<a class="code" href="structsha256__ctx.html#a21fb3008e4848b4432478a14ab53320b" title="摘要">digest</a>, ctx-&gt;<a class="code" href="structsha256__ctx.html#a6ed33b626cc641041136be1c87eaf9b8" title="计数">cnt</a>);
<a name="l00110"></a>00110 }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112 NV_API <span class="keywordtype">void</span> __sha256_update(<a class="code" href="structsha256__ctx.html" title="SHA-256上下文">sha256_ctx</a>* ctx, <a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>* buf, <span class="keywordtype">size_t</span> cnt);
<a name="l00113"></a>00113 
<a name="l00144"></a><a class="code" href="group__SHA-256__224.html#ga14a465a2682c74c519b1aff8eb1ddd81">00144</a> <span class="preprocessor">#define sha256_update(ctx, buf, cnt) __sha256_update(ctx, (uint8_t*)(buf), cnt)</span>
<a name="l00145"></a>00145 <span class="preprocessor"></span>
<a name="l00153"></a>00153 NV_API <span class="keywordtype">void</span> <a class="code" href="group__SHA-256__224.html#ga8b34382e94f499437c3645f912be9731" title="获取SHA256校验值">sha256_final</a>(<a class="code" href="structsha256__ctx.html" title="SHA-256上下文">sha256_ctx</a>* ctx, <span class="keywordtype">void</span>* digest);
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> __sha224_init(uint32_t* digest, uint32_t* cnt)
<a name="l00156"></a>00156 {
<a name="l00157"></a>00157     digest[0] = SHA224_HASH_H0;
<a name="l00158"></a>00158     digest[1] = SHA224_HASH_H1;
<a name="l00159"></a>00159     digest[2] = SHA224_HASH_H2;
<a name="l00160"></a>00160     digest[3] = SHA224_HASH_H3;
<a name="l00161"></a>00161     digest[4] = SHA224_HASH_H4;
<a name="l00162"></a>00162     digest[5] = SHA224_HASH_H5;
<a name="l00163"></a>00163     digest[6] = SHA224_HASH_H6;
<a name="l00164"></a>00164     digest[7] = SHA224_HASH_H7;
<a name="l00165"></a>00165     cnt[0] = 0;
<a name="l00166"></a>00166     cnt[1] = 0;
<a name="l00167"></a>00167 }
<a name="l00168"></a>00168 
<a name="l00174"></a><a class="code" href="group__SHA-256__224.html#gafad856587d338170b3124b9622fbc870">00174</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group__SHA-256__224.html#gafad856587d338170b3124b9622fbc870" title="初始化SHA224上下文">sha224_init</a>(sha224_ctx* ctx)
<a name="l00175"></a>00175 {
<a name="l00176"></a>00176     __sha224_init(ctx-&gt;digest, ctx-&gt;cnt);
<a name="l00177"></a>00177 }
<a name="l00178"></a>00178 
<a name="l00179"></a>00179 NV_API <span class="keywordtype">void</span> __sha224_update(sha224_ctx* ctx, <a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>* buf, <span class="keywordtype">size_t</span> cnt);
<a name="l00180"></a>00180 
<a name="l00211"></a><a class="code" href="group__SHA-256__224.html#ga4d601457ca2d51f9600dd61a29d66aa1">00211</a> <span class="preprocessor">#define sha224_update(ctx, buf, cnt) __sha256_update(ctx, (uint8_t*)(buf), cnt)</span>
<a name="l00212"></a>00212 <span class="preprocessor"></span>
<a name="l00220"></a><a class="code" href="group__SHA-256__224.html#ga79efe75a19b03d03c08884443723b979">00220</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group__SHA-256__224.html#ga79efe75a19b03d03c08884443723b979" title="获取SHA224校验值">sha224_final</a>(sha224_ctx* ctx, <span class="keywordtype">void</span>* digest)
<a name="l00221"></a>00221 {
<a name="l00222"></a>00222     <a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a> t[32];
<a name="l00223"></a>00223 
<a name="l00224"></a>00224     <a class="code" href="group__SHA-256__224.html#ga8b34382e94f499437c3645f912be9731" title="获取SHA256校验值">sha256_final</a>(ctx, t);
<a name="l00225"></a>00225     memcpy(digest, t, 28);
<a name="l00226"></a>00226     memset(t, 0, 32);
<a name="l00227"></a>00227 }
<a name="l00228"></a>00228 
<a name="l00231"></a>00231 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00232"></a>00232 <span class="preprocessor"></span>}
<a name="l00233"></a>00233 <span class="preprocessor">#endif  </span><span class="comment">/* #ifdef __cplusplus */</span>
<a name="l00234"></a>00234 
<a name="l00235"></a>00235 <span class="preprocessor">#endif </span><span class="comment">/* #ifndef __NV_SHA256__ */</span>
</pre></div></div>
</div>
<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>全部</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>数据结构</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>文件</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>函数</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>变量</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>类型定义</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>宏定义</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<hr class="footer"/><address class="footer"><small>Generated at 2015年七月16日 星期四 12:00:37 for Navo Portable Library by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
</body>
</html>
